<template>
	<div class="audit-wrapper">
		<!-- 审核确认弹框 -->
		<AuditConfirm ref="auditDialog" :submit="handleAudit" />
		<div class="head">
			<span class="title">
				收益审核详情
			</span>
			<div v-if="allowAudit" class="right-btn">
				<el-button plain @click="goBack">
					{{ $t('common.cancel') }}
				</el-button>
				<el-button
					v-if="hasPermission('90570059')"
					type="success"
					@click="() => $refs.auditDialog.successOpen()"
				>
					{{
						activeName === '1'
							? $t('funds.fund_audit.audit_success_1')
							: $t('funds.fund_audit.audit_success_2')
					}}
				</el-button>
				<el-button
					v-if="hasPermission('90570059')"
					type="danger"
					@click="() => $refs.auditDialog.dangerOpen()"
				>
					{{
						activeName === '1'
							? $t('funds.fund_audit.audit_fail_1')
							: $t('funds.fund_audit.audit_fail_2')
					}}
				</el-button>
			</div>
			<div v-else class="right-btn">
				<el-button plain @click="goBack">
					{{ $t('common.back') }}
				</el-button>
			</div>
		</div>
		<div class="audit-content detailBoxStyle flex-row-container">
			<div class="tree-box mr15">
				<CommonProxyTree
					ref="proxyTree"
					:selectedData.sync="selectedData"
					:detailData="detailData"
					:createdAtEnd="proxyCreatedAtEnd"
				/>
			</div>
			<div class="treeRight">
				<div v-if="selectedData.type === 1">
					<div class="contentBox mt30">
						代理账号信息
					</div>
					<el-table
						v-loading="loading"
						element-loading-spinner="el-icon-loading"
						size="mini"
						class="small-size-table"
						:data="[1]"
						style="width: 100%; margin: 15px 0"
						:header-cell-style="getRowClass"
						highlight-current-row
					>
						<el-table-column
							prop="userName"
							align="center"
							label="代理账号"
						>
							<template>
								{{ proxyAccountInfo.userName }}
							</template>
						</el-table-column>
						<el-table-column
							prop="userName"
							align="center"
							label="代理层级"
						>
							<template>
								{{ proxyAccountInfo.proxyLevel }}
							</template>
						</el-table-column>
						<el-table-column
							prop="userName"
							align="center"
							label="直属上级"
						>
							<template>
								{{ proxyAccountInfo.parentProxyName || '-' }}
							</template>
						</el-table-column>
						<el-table-column
							prop="userName"
							align="center"
							label="总代"
						>
							<template>
								{{ proxyAccountInfo.topProxyName }}
							</template>
						</el-table-column>
						<el-table-column
							prop="userName"
							align="center"
							label="业务模式"
						>
							<template>
								{{
									mappingBusinessModel(
										proxyAccountInfo.businessModel
									)
								}}
							</template>
						</el-table-column>
						<el-table-column
							key="accountStatus"
							prop="accountStatus"
							align="center"
							:label="$t('common.account_status')"
							min-width="115"
						>
							<template>
								<span
									v-if="!!proxyAccountInfo.paymentLockStatus"
									class="deleteRgba"
								>
									{{ $t('agent.charge_lock') }}
									<br />
								</span>
								<span v-if="false">
									{{ $t('agent.login_lock') }}：
								</span>
								<span
									v-if="!!proxyAccountInfo.loginLockStatus"
									class="disableRgba"
								>
									{{ $t('agent.login_lock') }}
								</span>
								<span
									v-if="!!proxyAccountInfo.gameLockStatus"
									class="lockingRgba"
								>
									{{ $t('agent.game_lock') }}
								</span>
								<span
									v-if="
										proxyAccountInfo.loginLockStatus ===
											0 &&
											proxyAccountInfo.paymentLockStatus ===
												0
									"
									class="normalRgba"
								>
									{{ $t('agent.normal') }}
								</span>
							</template>
						</el-table-column>
						<el-table-column
							prop="userName"
							align="center"
							label="注册时间"
						>
							<template>
								{{ proxyAccountInfo.createdAt || '-' }}
							</template>
						</el-table-column>
					</el-table>
					<div class="contentBox mt30 d-flex">
						<span>
							{{
								dayjs(
									String(detailData.startTime),
									'YYYYMMDD'
								).format('YYYY-MM-DD')
							}}
							-
							{{
								dayjs(
									String(detailData.endTime),
									'YYYYMMDD'
								).format('YYYY-MM-DD')
							}}
							期代理收益统计
						</span>
						<!-- <span>
							<el-button
								size="mini"
								type="primary"
								@click="dialogData()"
								v-if="!auditDetail.audit1Operator"
							>
								收益加减
							</el-button>
						</span> -->
					</div>
					<el-table
						v-loading="loading"
						element-loading-spinner="el-icon-loading"
						size="mini"
						class="small-size-table"
						:data="proxyIncomeList"
						style="width: 100%; margin: 15px 0"
						:header-cell-style="getRowClass"
						highlight-current-row
					>
						<el-table-column
							prop="userName"
							align="center"
							label="收益状态"
						>
							<template slot-scope="scope">
								<span
									v-if="scope.row.payoutStatus === 6"
									class="disableRgba"
								>
									已取消
								</span>
								<span
									v-if="scope.row.payoutStatus === 3"
									class="normalRgba"
								>
									已发放
								</span>
								<span
									v-if="scope.row.payoutStatus === 1"
									class="lockingRgba"
								>
									待发放
								</span>
								<span
									v-if="scope.row.payoutStatus === 5"
									class="deleteRgba"
								>
									无收益
								</span>
								<span
									v-if="scope.row.payoutStatus === 0"
									class="deleteRgba"
								>
									未结算
								</span>
								<span
									v-if="scope.row.payoutStatus === 2"
									class="deleteRgba"
								>
									待领取
								</span>
								<span
									v-if="scope.row.payoutStatus === 4"
									class="deleteRgba"
								>
									超时未领取
								</span>
							</template>
						</el-table-column>
						<el-table-column
							prop="userName"
							align="center"
							label="本期收益"
						>
							<template slot-scope="scope">
								<span>
									{{
										handleTotalNumber(
											'USDT',
											scope.row.currentIncomeAmount
										)
									}}
								</span>
							</template>
						</el-table-column>
						<el-table-column
							prop="userName"
							align="center"
							label="收益调整"
						>
							<template slot-scope="scope">
								{{
									handleTotalNumber(
										'USDT',
										scope.row.adjustIncomeAmount
									)
								}}
							</template>
						</el-table-column>
						<el-table-column
							prop="userName"
							align="center"
							label="调整后收益"
						>
							<template slot="header">
								<span>
									调整后收益
									<el-tooltip
										class="item"
										effect="dark"
										content="如果实发收益为负数，则记账的时候该代理的现金余额累加该数值，如果累加后现金余额为负数，则现金余额记录为负数；"
										placement="top-start"
									>
										<i class="el-icon-question"></i>
									</el-tooltip>
								</span>
							</template>
							<template slot-scope="scope">
								{{
									handleTotalNumber(
										'USDT',
										scope.row.realIncomeAmount
									)
								}}
							</template>
						</el-table-column>
						<el-table-column
							prop="userName"
							align="center"
							label="备注"
						>
							<template slot-scope="scope">
								<span>
									{{
										scope.row.audit1Desc
											? `${$t(
													'funds.proxy_member_funds_record.frirst_audit'
											  )}：${scope.row.audit1Desc}`
											: '-'
									}}
									<br v-show="scope.row.audit2Desc" />
									{{
										scope.row.audit2Desc
											? `${$t(
													'funds.proxy_member_funds_record.second_audit'
											  )}：${scope.row.audit2Desc}`
											: '-'
									}}
								</span>
							</template>
						</el-table-column>
					</el-table>
					<div class="contentBox mt30">
						收益详情
					</div>
					<el-table
						v-loading="loading"
						element-loading-spinner="el-icon-loading"
						size="mini"
						class="small-size-table"
						:data="incomeAuditDetail1"
						style="width: 100%; margin: 15px 0"
						:header-cell-style="getRowClass"
						highlight-current-row
					>
						<el-table-column
							prop="userName"
							align="center"
							label="项目"
						>
							德州俱乐部
						</el-table-column>
						<el-table-column
							prop="userName"
							align="center"
							label="服务费贡献"
							width="200"
						>
							<template slot="header">
								<span>
									服务费贡献
									<el-tooltip
										class="item"
										effect="dark"
										content="服务费贡献=手牌服务费贡献+局服务费贡献"
										placement="top-start"
									>
										<i class="el-icon-question"></i>
									</el-tooltip>
								</span>
							</template>
							<template slot-scope="scope">
								<el-link
									class="lightBlueColor"
									type="primary"
									@click="dialogData2()"
								>
									{{
										handleTotalNumber(
											'USDT',
											scope.row.clubAmount
										)
									}}
								</el-link>
							</template>
						</el-table-column>
						<el-table-column
							prop="userName"
							align="center"
							label="团队分成比例"
						>
							<template slot-scope="scope">
								{{ scope.row.rebateRate }}%
							</template>
						</el-table-column>
						<el-table-column
							prop="userName"
							align="center"
							label="团队分成金额"
						>
							<template slot-scope="scope">
								{{
									handleTotalNumber(
										'USDT',
										scope.row.rebateAmount
									)
								}}
							</template>
						</el-table-column>
						<el-table-column
							prop="userName"
							align="center"
							label="直属代理团队分成金额"
						>
							<template slot-scope="scope">
								{{
									handleTotalNumber(
										'USDT',
										scope.row.underProxyAmount
									)
								}}
							</template>
						</el-table-column>
						<el-table-column
							prop="userName"
							align="center"
							label="会员代理返水"
						>
							<template slot-scope="scope">
								{{
									handleTotalNumber(
										'USDT',
										scope.row.memberRebateAmountByProxy
									)
								}}
							</template>
						</el-table-column>
						<el-table-column
							prop="userName"
							align="center"
							label="实际应发分成金额"
						>
							<template slot="header">
								<span>
									实际应发分成金额
									<el-tooltip
										class="item"
										effect="dark"
										content="实际应发分成金额=团队分成金额-直属代理团队分成金额-会员代理返水"
										placement="top-start"
									>
										<i class="el-icon-question"></i>
									</el-tooltip>
								</span>
							</template>
							<template slot-scope="scope">
								{{
									handleTotalNumber(
										'USDT',
										scope.row.incomeAmount
									)
								}}
							</template>
						</el-table-column>
					</el-table>
					<el-table
						v-loading="loading"
						element-loading-spinner="el-icon-loading"
						size="mini"
						class="small-size-table"
						:data="incomeAuditDetail1"
						style="width: 100%; margin: 15px 0"
						:header-cell-style="getRowClass"
						highlight-current-row
					>
						<el-table-column
							prop="userName"
							align="center"
							label="项目"
						>
							德州保险
						</el-table-column>
						<el-table-column
							prop="userName"
							align="center"
							label="会员游戏输赢"
						>
							<template slot-scope="scope">
								{{
									handleTotalNumber(
										'USDT',
										scope.row.netAmount
									)
								}}
							</template>
						</el-table-column>
						<el-table-column
							prop="userName"
							align="center"
							label="团队分成比例"
						>
							<template slot-scope="scope">
								{{ scope.row.zhanchengRate }}%
							</template>
						</el-table-column>
						<el-table-column
							prop="userName"
							align="center"
							label="团队分成金额"
						>
							<template slot-scope="scope">
								{{
									handleTotalNumber(
										'USDT',
										scope.row.commissionNetAmount
									)
								}}
							</template>
						</el-table-column>
						<el-table-column
							prop="userName"
							align="center"
							label="直属代理团队分成金额"
						>
							<template slot-scope="scope">
								<p
									:style="
										handleNumberColor(
											scope.row.underProxyNetAmount
										)
									"
								>
									{{
										handleTotalNumber(
											'USDT',
											scope.row.underProxyNetAmount
										)
									}}
								</p>
							</template>
						</el-table-column>
						<el-table-column
							prop="userName"
							align="center"
							label="实际应发分成金额"
						>
							<template slot="header">
								<span>
									实际应发分成金额
									<el-tooltip
										class="item"
										effect="dark"
										content="实际应发分成金额=团队分成金额-直属代理团队分成金额"
										placement="top-start"
									>
										<i class="el-icon-question"></i>
									</el-tooltip>
								</span>
							</template>
							<template slot-scope="scope">
								{{
									handleTotalNumber(
										'USDT',
										scope.row.incomeNetAmount
									)
								}}
							</template>
						</el-table-column>
					</el-table>
					<el-table
						v-loading="loading"
						element-loading-spinner="el-icon-loading"
						size="mini"
						class="small-size-table"
						:data="incomeAuditDetail3"
						style="width: 100%; margin: 15px 0"
						:header-cell-style="getRowClass"
						highlight-current-row
					>
						<el-table-column
							prop="userName"
							align="center"
							label="项目"
						>
							德州增值服务
						</el-table-column>
						<el-table-column
							prop="userName"
							align="center"
							label="增值服务纯利"
							width="200"
						>
							<template slot-scope="scope">
								<!-- <el-link
									class="lightBlueColor"
									type="primary"
									@click="clubAmountDialogFn(scope.row)"
								>
									{{
										handleTotalNumber(
											'USDT',
											scope.row.clubAmount
										)
									}}
								</el-link> -->
								{{
									handleTotalNumber(
										'USDT',
										scope.row.clubAmount
									)
								}}
							</template>
						</el-table-column>
						<el-table-column
							prop="userName"
							align="center"
							label="团队分成比例"
						>
							<template slot-scope="scope">
								{{ scope.row.rebateRate }}%
							</template>
						</el-table-column>
						<el-table-column
							prop="userName"
							align="center"
							label="团队分成金额"
						>
							<template slot-scope="scope">
								{{
									handleTotalNumber(
										'USDT',
										scope.row.rebateAmount
									)
								}}
							</template>
						</el-table-column>
						<el-table-column
							prop="userName"
							align="center"
							label="直属代理团队分成金额"
						>
							<template slot-scope="scope">
								{{
									handleTotalNumber(
										'USDT',
										scope.row.underProxyAmount
									)
								}}
							</template>
						</el-table-column>
						<el-table-column
							prop="userName"
							align="center"
							label="实际应发分成金额"
						>
							<template slot="header">
								<span>
									实际应发分成金额
									<el-tooltip
										class="item"
										effect="dark"
										content="实际应发分成金额=团队分成金额-直属代理团队分成金额"
										placement="top-start"
									>
										<i class="el-icon-question"></i>
									</el-tooltip>
								</span>
							</template>
							<template slot-scope="scope">
								{{
									handleTotalNumber(
										'USDT',
										scope.row.incomeAmount
									)
								}}
							</template>
						</el-table-column>
					</el-table>
					<el-table
						v-loading="loading"
						element-loading-spinner="el-icon-loading"
						size="mini"
						class="small-size-table"
						:data="incomeAuditDetail2"
						style="width: 100%; margin: 15px 0"
						:header-cell-style="getRowClass"
						highlight-current-row
					>
						<el-table-column
							prop="userName"
							align="center"
							label="项目"
						>
							<template slot-scope="scope">
								{{ scope.row.venueName }}
							</template>
						</el-table-column>
						<el-table-column
							prop="userName"
							align="center"
							label="会员有效投注"
						>
							<template slot-scope="scope">
								{{
									handleTotalNumber(
										'USDT',
										scope.row.clubAmount
									)
								}}
							</template>
						</el-table-column>
						<el-table-column
							prop="userName"
							align="center"
							label="团队返点比例"
						>
							<template slot-scope="scope">
								{{
									scope.row.venueName == '合计'
										? '-'
										: scope.row.rebateRate + '%'
								}}
							</template>
						</el-table-column>
						<el-table-column
							prop="userName"
							align="center"
							label="团队返点金额"
						>
							<template slot-scope="scope">
								{{
									handleTotalNumber(
										'USDT',
										scope.row.rebateAmount
									)
								}}
							</template>
						</el-table-column>
						<!-- <el-table-column
							prop="userName"
							align="center"
							label="团队占成比例"
						>
							<template slot-scope="scope">
								{{
									scope.row.venueName == '合计'
										? '-'
										: scope.row.zhanchengRate + '%'
								}}
							</template>
						</el-table-column>

						<el-table-column
							prop="partRebateAmount"
							align="center"
							label="返点成本分摊"
						>
							<template slot="header">
								<span>
									返点成本分摊
									<el-tooltip
										class="item"
										effect="dark"
										placement="top-start"
									>
										<div slot="content">
											返点成本分摊=团队返点成本分摊-下级返点成本分摊
										</div>
										<i class="el-icon-question"></i>
									</el-tooltip>
								</span>
							</template>
							<template slot-scope="scope">
								{{
									handleTotalNumber(
										'USDT',
										scope.row.partRebateAmount
									)
								}}
							</template>
						</el-table-column> -->
						<el-table-column
							prop="userName"
							align="center"
							label="直属代理团队返点金额"
						>
							<template slot-scope="scope">
								{{
									handleTotalNumber(
										'USDT',
										scope.row.underProxyAmount
									)
								}}
							</template>
						</el-table-column>
						<el-table-column
							prop="userName"
							align="center"
							label="会员代理返水"
						>
							<template slot-scope="scope">
								{{
									handleTotalNumber(
										'USDT',
										scope.row.memberRebateAmountByProxy
									)
								}}
							</template>
						</el-table-column>
						<el-table-column
							prop="userName"
							align="center"
							label="实际应发返点金额"
						>
							<template slot="header">
								<span>
									实际应发返点金额
									<el-tooltip
										class="item"
										effect="dark"
										placement="top-start"
									>
										<div slot="content">
											实际应发返点金额=团队返点金额-直属代理团队返点金额-会员代理返水
										</div>
										<i class="el-icon-question"></i>
									</el-tooltip>
								</span>
							</template>
							<template slot-scope="scope">
								{{
									handleTotalNumber(
										'USDT',
										scope.row.incomeAmount
									)
								}}
							</template>
						</el-table-column>
					</el-table>

					<!-- <el-table
						v-loading="loading"
						element-loading-spinner="el-icon-loading"
						size="mini"
						class="small-size-table"
						:data="incomeAuditDetail2"
						style="width: 100%; margin: 15px 0"
						:header-cell-style="getRowClass"
						highlight-current-row
					>
						<el-table-column
							prop="userName"
							align="center"
							label="项目"
						>
							<template slot-scope="scope">
								{{ scope.row.venueName }}
							</template>
						</el-table-column>
						<el-table-column
							prop="userName"
							align="center"
							label="累计会员游戏输赢"
						>
							<template slot-scope="scope">
								{{
									handleTotalNumber(
										'USDT',
										scope.row.netAmount
									)
								}}
							</template>
						</el-table-column>
						<el-table-column
							prop="userName"
							align="center"
							label="团队占成比例"
						>
							<template slot-scope="scope">
								{{
									scope.row.venueName == '合计'
										? '-'
										: scope.row.zhanchengRate + '%'
								}}
							</template>
						</el-table-column>
						<el-table-column
							prop="userName"
							align="center"
							label="团队占成金额"
						>
							<template slot-scope="scope">
								{{
									handleTotalNumber(
										'USDT',
										scope.row.commissionNetAmount
									)
								}}
							</template>
						</el-table-column>
						<el-table-column
							prop="userName"
							align="center"
							label="直属代理团队占成金额"
						>
							<template slot-scope="scope">
								<p
									:style="
										handleNumberColor(
											scope.row.underProxyNetAmount
										)
									"
								>
									{{
										handleTotalNumber(
											'USDT',
											scope.row.underProxyNetAmount
										)
									}}
								</p>
							</template>
						</el-table-column>
						<el-table-column
							prop="userName"
							align="center"
							label="实际应发占成金额"
						>
							<template slot="header">
								<span>
									实际应发占成金额
									<el-tooltip
										class="item"
										effect="dark"
										placement="top-start"
									>
										<div slot="content">
											实际应发占成金额=团队占成金额-直属代理团队占成金额
										</div>
										<i class="el-icon-question"></i>
									</el-tooltip>
								</span>
							</template>
							<template slot-scope="scope">
								{{
									handleTotalNumber(
										'USDT',
										scope.row.incomeNetAmount
									)
								}}
							</template>
						</el-table-column>
					</el-table> -->

					<template
						v-if="detailData.proxyName === selectedData.userName"
					>
						<div
							class="block mt20 pr10"
							v-if="auditDetail.audit1Operator"
						>
							<p class="name">
								{{ $t('funds.fund_audit.audit_info') }}
							</p>
							<div class="block-content">
								<el-row>
									<el-col :span="8" :offset="0">
										{{
											$t('funds.fund_audit.audit_user_1')
										}}:
										{{ auditDetail.audit1Operator || '-' }}
									</el-col>
									<el-col :span="8" :offset="0">
										{{
											$t('funds.fund_audit.audit_time_1')
										}}:
										{{ auditDetail.audit1Time || '-' }}
									</el-col>
									<el-col :span="8" :offset="0">
										{{
											$t(
												'funds.fund_audit.audit_remark_1'
											)
										}}:
										<span class="txtfeed">
											{{ auditDetail.audit1Desc || '-' }}
										</span>
									</el-col>
								</el-row>
							</div>
							<div
								v-if="auditDetail.audit2Operator"
								class="block-content"
							>
								<el-row>
									<el-col :span="8" :offset="0">
										{{
											$t('funds.fund_audit.audit_user_2')
										}}:
										{{ auditDetail.audit2Operator || '-' }}
									</el-col>
									<el-col :span="8" :offset="0">
										{{
											$t('funds.fund_audit.audit_time_2')
										}}:
										{{ auditDetail.audit2Time || '-' }}
									</el-col>
									<el-col :span="8" :offset="0">
										{{
											$t(
												'funds.fund_audit.audit_remark_2'
											)
										}}:
										<span class="txtfeed">
											{{ auditDetail.audit2Desc || '-' }}
										</span>
									</el-col>
								</el-row>
							</div>
						</div>
					</template>
				</div>
				<RebateBouns
					v-else
					:selectedData="selectedData"
					:detailData="detailData"
				/>
			</div>
		</div>

		<!-- 审核弹窗 -->
		<el-dialog
			:title="$t('funds.fund_audit.audit_dialog_title')"
			center
			:visible.sync="auditDialog.visible"
			width="630px"
			class="audit-dialog"
			@close="closeAuditDialog"
			:close-on-click-modal="false"
		>
			<el-form
				ref="reviwewForm"
				:model="auditDialog"
				:rules="formRules"
				label-width="auto"
			>
				<el-form-item
					:label="$t('common.components.remark')"
					prop="remark"
				>
					<el-input
						v-model="auditDialog.remark"
						clearable
						type="textarea"
						:maxlength="500"
						show-word-limit
						:autosize="{ minRows: 4, maxRows: 4 }"
						v-input="{ name: 'noEmpty' }"
						style="width: 380px"
						:placeholder="$t('common.please_enter')"
					></el-input>
				</el-form-item>
			</el-form>
			<div slot="footer" class="dialog-footer">
				<el-button
					:disabled="auditDialog.loading"
					@click="auditDialog.visible = false"
				>
					{{ $t('common.cancel') }}
				</el-button>
				<el-button
					type="primary"
					:disabled="auditDialog.loading"
					@click="openSeaMoonDialog(true)"
				>
					<i v-show="auditDialog.loading" class="el-icon-loading"></i>
					<span>{{ $t('common.submit') }}</span>
				</el-button>
			</div>
		</el-dialog>
		<el-dialog
			:visible.sync="rulesDialog.visible"
			:destroy-on-close="true"
			width="1000px"
			:title="`${$t('funds.fund_audit.return_rule')}`"
		>
			<el-table
				v-loading="loading"
				element-loading-spinner="el-icon-loading"
				border
				size="mini"
				:data="rulesDialog.tableData"
				:height="400"
				style="width: 100%;"
				:header-cell-style="getRowClass"
				:row-class-name="tableRowClassName"
			>
				<el-table-column
					align="center"
					type="index"
					:label="$t('common.serial_number')"
				></el-table-column>
				<el-table-column
					align="center"
					:label="`${$t('funds.fund_audit.team_water')}`"
					prop="validBetAmount"
				>
					<template slot-scope="scope">
						<span>
							≥ {{ handleCurrency(detailData.currency) }}
							{{
								handleNumber(
									detailData.currency,
									scope.row.validBetAmount
								)
							}}
						</span>
					</template>
				</el-table-column>

				<el-table-column
					align="center"
					:label="$t('funds.fund_audit.active_subordinate')"
					prop="activeUsers"
				>
					<template slot-scope="scope">
						<span>
							≥
							{{
								!!scope.row.activeUsers ||
								scope.row.activeUsers === 0
									? scope.row.activeUsers
									: '-'
							}}
						</span>
					</template>
				</el-table-column>
				<el-table-column
					align="center"
					:label="
						$t('funds.fund_audit.effective_Number_of_active_unit')
					"
					prop="effecactiveUsers"
				>
					<template slot-scope="scope">
						<span>
							≥
							{{
								!!scope.row.effecactiveUsers ||
								scope.row.effecactiveUsers === 0
									? scope.row.effecactiveUsers
									: '-'
							}}
						</span>
					</template>
				</el-table-column>
				<el-table-column
					align="center"
					:label="`${$t('funds.fund_audit.rebate_rate')}`"
					prop="rebateRate"
				>
					<template slot-scope="scope">
						<span>
							{{ handlePercentage(scope.row.rebateRate) }}
						</span>
					</template>
				</el-table-column>
			</el-table>
		</el-dialog>
		<el-dialog
			:visible="addVisible"
			width="500px"
			:destroy-on-close="true"
			title="收益加减"
			class="rempadding"
			:before-close="handleClose"
		>
			<el-form
				:model="addIncome"
				:rules="rules"
				ref="addIncome"
				label-width="130px"
				class="demo-ruleForm"
			>
				<el-form-item
					label="调整类型:"
					prop="adjustType"
					style="margin-top: 20px;"
				>
					<el-radio v-model="radio" label="1">
						收益增加
					</el-radio>
					<el-radio v-model="radio" label="0">
						收益减少
					</el-radio>
				</el-form-item>
				<el-form-item label="调整金额:" prop="addIncomeMoney">
					<el-input v-model="addIncomeMoney" type="number"></el-input>
				</el-form-item>
				<el-form-item label="调整前本期应发:" prop="before">
					<span>
						{{ handleTotalNumber('USDT', currentIncomeAmount) }}
					</span>
				</el-form-item>

				<el-form-item label="调整后实发收益:" prop="after">
					<span>
						{{ handleTotalNumber('USDT', addIncome.after) }}
					</span>
				</el-form-item>
				<el-form-item label="备注:">
					<el-input
						type="textarea"
						v-model="addIncome.remark"
					></el-input>
				</el-form-item>
			</el-form>
			<div slot="footer" class="dialog-footer" style="text-align: center">
				<el-button @click="addVisible = false">取消</el-button>
				<el-button type="primary" @click="revenueAdjustAmountFun()">
					确定
				</el-button>
			</div>
		</el-dialog>
		<el-dialog
			:visible="detailVisible"
			width="700px"
			:destroy-on-close="true"
			:title="
				'代理' +
					proxyAccountInfo.userName +
					'的德州俱乐部服务费贡献详情'
			"
			class="rempadding"
			:before-close="handleClose2"
		>
			<div style="padding:20px;">
				<div
					style="display: flex;justify-content: space-around;margin: 20px 0;"
				>
					<span>代理账号:{{ proxyAccountInfo.userName }}</span>
					<span>代理层级:{{ proxyAccountInfo.proxyLevel }}</span>
					<span>
						直属上级:{{ proxyAccountInfo.parentProxyName || '-' }}
					</span>
					<span>总代理:{{ proxyAccountInfo.topProxyName }}</span>
					<span>
						业务模式:{{
							mappingBusinessModel(proxyAccountInfo.businessModel)
						}}
					</span>
				</div>
				<div>
					<el-table
						:data="detailTableData"
						border
						style="width: 100%"
					>
						<el-table-column
							prop="project"
							label="项目"
							align="center"
						></el-table-column>
						<el-table-column
							prop="serviceChargeHandContribution"
							label="手牌服务费贡献"
							align="center"
						></el-table-column>
						<el-table-column
							prop="serviceChargeRoundContribution"
							label="局服务费贡献"
							align="center"
						></el-table-column>
						<el-table-column
							prop="serviceAmountContribution"
							label="总计服务费贡献"
							align="center"
						></el-table-column>
					</el-table>
				</div>
			</div>
		</el-dialog>
		<SeaMoonDialog
			:sea-moon-visible.sync="seaMoon.visible"
			:params="seaMoon.params"
			@success="onSeaMoonValidSucceed"
		></SeaMoonDialog>
		<ClubAmountDialog
			v-if="clubAmountDialog"
			:visible.sync="clubAmountDialog"
			@handleVisible="clubAmountDialog = false"
			:curData="clubAmountVal"
		></ClubAmountDialog>
	</div>
</template>

<script>
import list from '@/mixins/list'
import dayjs from 'dayjs'
import SeaMoonDialog from '@/components/SeaMoon'
import CommonProxyTree from '@/components/CommonProxyTree/index'
import RebateBouns from '@/components/Funds/RebateBouns'
// import ProxyRebate from '@/components/Funds/ProxyRebate'
import ClubAmountDialog from './clubAmountDialog.vue'
import AuditConfirm from '@/components/AuditConfirm'

export default {
	components: {
		SeaMoonDialog,
		CommonProxyTree,
		RebateBouns,
		// ProxyRebate,
		ClubAmountDialog,
		AuditConfirm
	},
	mixins: [list],
	props: {
		allowAudit: {
			type: Boolean,
			required: true
		},
		activeName: {
			type: String,
			required: true
		},
		detailData: {
			type: Object,
			required: true
		}
	},

	data() {
		return {
			addVisible: false,
			radio: '1',
			addIncomeMoney: 0,
			addIncome: {
				money: '',
				radio: '1',
				before: '0',
				after: '0',
				remark: ''
			},
			clubAmountDialog: false,
			clubAmountVal: null,
			currentIncomeAmount: 0,
			rules: {
				money: [
					{
						required: true,
						message: '请输入调整金额',
						trigger: 'blur'
					}
				],
				radio: [
					{
						required: true,
						message: '请选择调整类型',
						trigger: 'blur'
					}
				],
				before: [
					{
						required: true,
						message: '调整前本期应发',
						trigger: 'blur'
					}
				],
				after: [
					{
						required: true,
						message: '调整后实发收益',
						trigger: 'blur'
					}
				]
			},
			detailVisible: false,
			detailTableData: [],
			dayjs,
			proxyAccountInfo: {},
			proxyIncomeList: [],
			rowVal: {},
			tableLoading: false,
			showDialog: false,
			selectedData: {
				type: 1,
				userName: ''
			},
			// 活跃弹窗
			activeNumDialog: {
				rowData: {},
				loading: false,
				visible: false,
				title: '活跃人数',
				type: 1, // 1:active  2:validActive
				tableData: [],
				page: {
					total: 0,
					loading: false,
					pageNum: 1,
					pageSize: 100
				}
			},
			// 规则弹窗
			rulesDialog: {
				visible: false,
				level: undefined,
				tableData: []
			},
			// 审核弹窗
			auditDialog: {
				loading: false,
				visible: false,
				result: undefined,
				remark: undefined
			},
			seaMoon: {
				isAudit: false,
				visible: false,
				params: {}
			},
			incomeAuditDetail1: [],
			incomeAuditDetail2: [],
			incomeAuditDetail3: [],
			auditDetail: {},
			getAdjustAmountData: {}
		}
	},
	computed: {
		formRules() {
			return {
				remark: [
					{
						required: true,
						message: this.$t('funds.fund_audit.form_rules_tip2'),
						trigger: 'blur'
					},
					{
						min: 2,
						max: 500,
						message: this.$t('funds.fund_audit.form_rules_tip2'),
						trigger: 'blur'
					}
				]
			}
		},
		proxyCreatedAtEnd() {
			return dayjs(String(this.detailData?.endTime)).format(
				'YYYY-MM-DD 23:59:59'
			)
		},
		realIncomeData() {
			return [
				{
					realIncomeAmount: this.detailData.realIncomeAmount,
					adjustIncomeAmount: this.detailData.adjustIncomeAmount,
					currentIncomeAmount: this.detailData.currentIncomeAmount,
					payoutStatus: this.detailData.payoutStatus,
					audit1Desc: this.detailData.audit1Desc,
					audit2Desc: this.detailData.audit2Desc
				}
			]
		}
	},
	watch: {
		selectedData: {
			handler(next) {
				if (next.type === 1 && next.userName) {
					// this.proxyRebateDetail = {
					// 	proxyId: this.selectedData.id,
					// 	reportType: this.activeTab,
					// 	reportDate: this.detailData.reportDate
					// }
					// this.selecteSumaryKey = Math.random()
					// this.selecteDetailKey = Math.random()
					// this.getProxyAccountDetail()
					this.getData()
				}
			},
			immediate: true
		},
		radio: {
			handler(newVal) {
				if (this.radio == '1') {
					this.addIncome.after =
						parseFloat(this.currentIncomeAmount) +
						parseFloat(this.addIncomeMoney)
				} else {
					this.addIncome.after =
						parseFloat(this.currentIncomeAmount) -
						parseFloat(this.addIncomeMoney)
				}
			}
		},
		addIncomeMoney: {
			handler(newVal) {
				newVal = parseFloat(newVal) // 将字符串转换为浮点数
				if (!isNaN(newVal)) {
					// 确保转换成功
					if (this.radio == '1') {
						this.addIncome.after = this.currentIncomeAmount + newVal
					} else {
						this.addIncome.after = this.currentIncomeAmount - newVal
					}
				}
			}
		}
	},
	created() {},
	mounted() {
		// this.getData()
	},
	methods: {
		clubAmountDialogFn() {
			this.clubAmountVal = this.auditDetail
			this.clubAmountDialog = true
		},
		dialogData() {
			this.addIncomeMoney = 0
			this.$api
				.getAdjustAmount({
					reportDate: this.detailData.reportDate,
					proxyId: this.selectedData.id,
					businessModel: this.proxyAccountInfo.businessModel || 0
				})
				.then((res) => {
					this.getAdjustAmountData = res.data
					this.currentIncomeAmount = this.getAdjustAmountData.beforeIssueShouldAmount
					this.addIncome.after = this.getAdjustAmountData.beforeIssueShouldAmount
					this.addVisible = true
				})
		},
		handleClose() {
			this.addVisible = false
		},
		dialogData2() {
			this.detailVisible = true
			this.queryServiceRateAmountFun()
		},
		handleClose2() {
			this.detailVisible = false
		},
		getData() {
			this.loading = true
			this.$api
				.queryAgentDetailNew({
					reportDate: this.detailData.reportDate,
					merchantId: this.detailData.merchantId,
					proxyName:
						this.selectedData.userName || this.detailData.proxyName
				})
				.then((res) => {
					if (res?.code === 200) {
						this.proxyAccountInfo = res.data || {}
					}
				})
			this.$api
				.proxyIncomeList({
					cycleStartDate: this.detailData.startTime,
					cycleEndDate: this.detailData.endTime,
					proxyName: this.selectedData.userName
				})
				.then((res) => {
					if (res?.data?.record.length == 0) {
						this.loading = false
						this.incomeAuditDetail1 = []
						this.incomeAuditDetail2 = []
						this.incomeAuditDetail3 = []
						this.auditDetail = []
					}
					if (res?.code === 200) {
						this.proxyIncomeList = res.data.record || []
						this.currentIncomeAmount =
							res.data.record[0].currentIncomeAmount
						this.$api
							.proxyIncomeAuditDetail({
								id: res.data.record[0].orderNo
							})
							.then((res) => {
								this.loading = false
								this.auditDetail = res.data
								this.incomeAuditDetail1 =
									(res.data.fundsAuditDetailRespList &&
										res.data.fundsAuditDetailRespList.filter(
											(ele) =>
												ele.venueName.includes('俱乐部')
										)) ||
									[]
								this.incomeAuditDetail3 =
									(res.data.fundsAuditDetailRespList &&
										res.data.fundsAuditDetailRespList.filter(
											(ele) =>
												ele.venueName.includes('增值')
										)) ||
									[]
								this.incomeAuditDetail2 =
									(res.data.fundsAuditDetailRespList &&
										res.data.fundsAuditDetailRespList.filter(
											(ele) =>
												!ele.venueName.includes('德州')
										)) ||
									[]
							})
							.catch(() => {
								this.loading = false
							})
					}
				})
		},
		onSeaMoonValidSucceed(data) {
			if (this.seaMoon.isAudit) {
				this.handleAudit()
			}
		},
		openSeaMoonDialog(isAudit) {
			this.$refs.reviwewForm.validate((valid) => {
				if (valid) {
					this.handleAudit()
				}
			})
		},
		tableRowClassName({ row, rowIndex }) {
			return row.level === this.rulesDialog.level ? 'high-light' : ''
		},
		goBack() {
			this.$emit('goBack')
		},
		// 一审二审弹窗
		openAuditDialog(status) {
			this.auditDialog.result = status
			this.auditDialog.visible = true
		},
		closeAuditDialog() {
			this.$refs.reviwewForm.resetFields()
		},
		handleAudit(form) {
			this.auditDialog.loading = true
			const params = {
				ids: [this.detailData.orderNo],
				auditStatus: form.status,
				remark: form.remark
			}
			const loading = this.$loading({
				lock: true,
				text: 'Loading',
				spinner: 'el-icon-loading',
				background: 'rgba(0, 0, 0, 0.7)'
			})
			this.$api
				.proxyIncomeAuditRecord(params)
				.then((res) => {
					loading.close()
					this.$message({
						type: 'success',
						message: this.$t('common.action_success')
					})
					this.visible = false
					this.auditDialog.loading = false
					this.$emit('goBack', true)
				})
				.catch(() => {
					loading.close()
					this.visible = false
					this.auditDialog.loading = false
				})
		},
		revenueAdjustAmountFun() {
			console.log(this.detailData)
			const params = {
				adjustAmount: Number(this.addIncomeMoney),
				adjustType: Number(this.radio),
				afterIssueShouldAmount: Number(this.addIncome.after),
				beforeIssueShouldAmount: Number(this.currentIncomeAmount),
				cycleEndDate: this.getAdjustAmountData.cycleEndDate,
				cycleStartDate: this.getAdjustAmountData.cycleStartDate,
				merchantId: this.getAdjustAmountData.merchantId,
				merchantName: this.getAdjustAmountData.merchantName,
				proxyId: this.getAdjustAmountData.proxyId,
				proxyName: this.getAdjustAmountData.proxyName,
				remark: this.addIncome.remark,
				reportDate: this.getAdjustAmountData.reportDate,
				businessModel: this.proxyAccountInfo.businessModel || 0
			}
			const loading = this.$loading({
				lock: true,
				text: 'Loading',
				spinner: 'el-icon-loading',
				background: 'rgba(0, 0, 0, 0.7)'
			})
			this.$api
				.revenueAdjustAmount(params)
				.then((res) => {
					loading.close()
					this.addIncomeMoney = 0
					this.radio = '1'
					this.addIncome.after = 0
					this.addVisible = false
					this.addIncome.remark = ''
					this.getData()
					this.$message({
						type: 'success',
						message: this.$t('common.action_success')
					})
				})
				.catch(() => {
					loading.close()
					this.visible = false
					this.auditDialog.loading = false
				})
		},
		queryServiceRateAmountFun() {
			this.detailTableData = []
			const params = {
				proxyId: this.selectedData.id,
				reportDate: this.detailData.startTime
			}
			const loading = this.$loading({
				lock: true,
				text: 'Loading',
				spinner: 'el-icon-loading',
				background: 'rgba(0, 0, 0, 0.7)'
			})
			this.$api
				.queryServiceRateAmount(params)
				.then((res) => {
					loading.close()
					const e = res.data.serviceAmountRateRespDTO
					const e1 = {
						project: e.venueName,
						serviceChargeHandContribution: this.handleTotalNumber(
							'USDT',
							e.serviceChargeHandContribution
						),
						serviceChargeRoundContribution: this.handleTotalNumber(
							'USDT',
							e.serviceChargeRoundContribution
						),
						serviceAmountContribution: this.handleTotalNumber(
							'USDT',
							e.serviceAmountContribution
						)
					}
					const e2 = {
						project: '占比',
						serviceChargeHandContribution: this.handlePercentage(
							e.serviceChargeHandContributionRate
						),
						serviceChargeRoundContribution: this.handlePercentage(
							e.serviceChargeRoundContributionRate
						),
						serviceAmountContribution: this.handlePercentage(
							e.serviceAmountContributionRate
						)
					}
					this.detailTableData.push(e1)
					this.detailTableData.push(e2)
				})
				.catch(() => {
					loading.close()
					this.visible = false
					this.auditDialog.loading = false
				})
		}
	}
}
</script>

<style lang="scss" scoped>
.tree-box {
	width: 320px;
	flex-shrink: 0;
	height: auto;
	overflow: auto;
	::v-deep .el-card__body {
		padding-left: 0px;
		width: 100%;
	}
}
::v-deep .el-tabs__item {
	font-size: 16px;
	font-weight: bold;
}
.treeRight {
	width: calc(100% - 245px);
	// display: flex;
	// -o-display: flex;
	// -ms-display: flex;
	// -webkit-display: flex;
	// -moz-display: flex;
	// flex-direction: column;
	// -o-flex-direction: column;
	// -ms-flex-direction: column;
	// -webkit-flex-direction: column;
	// -moz-flex-direction: column;
	overflow-y: auto;
	overflow-x: hidden;
}
.txtfeed {
	width: 160px;
	table-layout: fixed;
	word-break: break-all;
	overflow: hidden;
}
.audit-wrapper {
	color: #666666;
	margin: 24px 16px 20px 16px;
	.head {
		height: 70px;
		line-height: 70px;
		width: 100%;
		background: #000;
		border-radius: 2px;
		padding: 0 30px;
		.title {
			font-weight: 600;
			color: rgb(192, 190, 190);
		}
		.right-btn {
			float: right;
		}
	}

	.audit-content {
		.block {
			padding: 10px 30px 0px 30px;
			.name {
				font-weight: 600;
				color: #303133;
			}
			.block-content {
				position: relative;
				width: 100%;
				margin-top: 15px;
			}
		}
		.rebate-details {
			padding-bottom: 20px;
			.details-page {
				margin-top: 10px;
				position: absolute;
				right: 0;
			}
		}
	}
}

.count-single-row {
	height: 40px;
	p {
		height: 40px;
		line-height: 40px;
		color: #5c5c5c;
		font-weight: 700;
		span {
			display: inline-block;
			width: 20px;
			height: 20px;
		}
	}
}

.audit-dialog {
	::v-deep .el-dialog__header {
		color: #909399;
		font-weight: 700;
		text-align: center;
	}
}

.active-dialog {
	::v-deep .el-dialog__header {
		padding: 10px 20px 10px;
	}
	::v-deep .el-dialog__body {
		padding: 20px 20px;
	}
	.tabs-wrapper {
		display: flex;
		.tab {
			width: 120px;
			height: 40px;
			line-height: 40px;
			text-align: center;
			border: 1px solid rgba(0, 0, 0, 0.15);
			font-size: 14px;
			font-weight: 600;
			color: #000000a3;
			cursor: pointer;
			margin-right: 20px;
		}
	}
	.active {
		background: #00bfbf;
	}
	.type-name {
		padding: 0 0 20px;
		font-weight: 600;
		.num {
			color: blue;
		}
	}
}
::v-deep .el-table {
	.high-light {
		color: #0dc5e3;
	}
}
.detailBoxStyle {
	border: none !important;
	margin-top: 10px;
	overflow: hidden;
}

::v-deep .rempadding .el-dialog__header {
	color: #909399;
	font-weight: 700;
}
::v-deep .rempadding .el-dialog__body {
	padding: 0;
	padding-bottom: 30px;
	.contentBox {
		display: flex;
		justify-content: space-between;
		align-items: center;
	}

	.contentBox,
	form {
		padding: 0 20px;
	}
}

.d-flex {
	display: flex;
	justify-content: space-between;
}
::v-deep .el-icon-question:after {
	font-size: 16px;
	margin-left: 0;
}
</style>
